home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Wildcat Files 2
/
The Wildcat Files 2 (Arsenal Computer).ISO
/
wildcat
/
wcfaxdb.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-06-14
|
10KB
|
333 lines
{$I WCDEFINE.INC}
{RESPONSIBILITY SLR}
unit WCFAXDB;
interface
uses
Dos,
{$IFDEF OPRO}
OpDos,
OPDate,
OpString,
{$ELSE}
TpDos,
TpDate,
TpString,
{$ENDIF}
WcType,
WcErr,
IsamTool,
Filer,
NumKeys,
WcGlobal,
WCDB;
const
MaxBusies = 5;
MaxErrors = 3;
FAXCreateTimeKey = 1;
FAXToFAXNumber = 2;
FAXUserNameKey = 3;
FAXSentTimeKey = 4;
FAXStatusKey = 5;
type
Str12 = String[12];
Str19 = String[19];
Str25 = String[25];
Str20 = String[20];
TFaxType = (ftLocal, ftMetro, ftRegional, ftLDistance, ftOSeas);
TFaxPhoneRec = record
AreaCode : String[3];
StNumber : String[20];
EndNumber : String[20];
Location : String[19];
NumberType : TFaxType;
end;
{---------------------------}
TFaxStatus = (fsPending,
fsSending,
fsSent,
fsError,
fsNotSent,
fsVoice,
fsBusy); {Status of job}
TFaxDocumentList = array[1..99] of String[20]; {Actual document names pending}
PFaxRec = ^TFaxRec;
TFaxRec = record
Del : LongInt;
LocalId : String[20]; {Node Name, Sysop Name}
ToSystem : String[27]; {To Company etc.}
ToName : String[30]; {To Name of person}
ToNumber : String[19]; {To Fax Number}
FromSystem : String[27]; {From SystemName}
FromName : String[30]; {From User Name}
Subject : String[30]; {Subject of FAX}
DialString : String; {To Fax Number with Prefix etc...}
FaxType : TFaxType; {Destination type}
CreateDate : DateTimeRec; {Create Date & Time}
SentDate : DateTimeRec; {Sent Date & Time}
Documents : TFaxDocumentList; {Document List}
RasFileName : String[12]; {Rasterized file name}
DialAttempts : Byte; {Dial Attempts}
SendAttempts : Byte; {Send Attempts}
Status : TFaxStatus; {Status of FAX document}
TotalPages : Word; {Total pages of fax}
TotalCost : LongInt; {Total cost of document}
Fine : Boolean;
MsgBytes : Word; {Total Number of characters in Message}
ToId : LongInt; {UserId of person to send to}
OrigNodeId : Byte; {Originators Node Id for create key}
Filler : array[1..95] of Byte; {Nada}
end;
{----------------------}
TDocArray = Array [1..10] of PathStr;
TFAXListRec = record {WCFAX.LST}
Name : String[20]; {Name of Document}
Desc : String[75]; {Description of Document}
Doc : TDocArray; {Array of paths to docs}
TotalPages : Word; {Total pages of Document}
CreationDate : Date; {Creationdate}
TimesSent : Word; {Times document save}
Cost : LongInt; {Cost by send type}
Secs : TArray1000Bits; {Security Level Bits}
end;
{----------------------}
const
dSunday = $01;
dMonday = $02;
dTuesday = $04;
dWednesday = $08;
dThursday = $10;
dFriday = $20;
dSaturday = $40;
type
TFaxSpec = record
Prefix : String[20]; {String sent before the number}
Suffix : String[20]; {String sent after the number}
StartTime, {Time to start processing these faxes}
EndTime : Time; {Time to end processing these faxes}
Days : Byte; {Days of week that we process these faxes}
end;
TFaxTypeArray = array[TFaxType] of TFaxSpec;
TFAXConfig = Record {WCFAX.CFG}
WCFAXPath : PathStr; {Location of WCFAX files}
OriginalPath : PathStr; {Location of Raw documents}
PendingPath : PathStr; {Location of Rasterized files}
FaxCoverPath : PathStr; {Cover page path and filename}
ConferenceNum : Word; {Conference where messages sent}
InternationalMode : Boolean; {Use Free form phone numbers}
Status : Boolean; {Display status during FAX Send}
{Following is stuff pertaining to the Server sending Faxes}
SBaud : LongInt; {FAXSERVERs FAX baud rate}
SLastAttemptBaud : LongInt; {FAXSERVERs Last attempt FAX baud rate}
SPreDial : String[20]; {PreDial command goes before dial prefix}
SDialCommand : String[20]; {Servers dial commmand i.e. ATDT}
SecuritySpecifics : TFaxTypeArray;{Fax specifics regarding time of day etc}
end;
{Flags for the WCFAX.SEC file}
const
fsFAXFineMode = $0001;
fsFAXViewMode = $0002;
fsFAXSysopMode = $0004;
fsFAXChangeName = $0008;
fsFAXEditor = $0010;
ntOverSeas = $0020;
ntLongDistance = $0040;
ntRegional = $0080;
ntMetro = $0100;
ntLocal = $0200;
{----------------------}
type
PFaxDatabase = ^TFaxDatabase;
TFAXDatabase = object(TFileBlock)
constructor Init;
destructor Done; virtual;
function DataLen(const Data) : Word; virtual;
procedure GetCreateInfo(var Len : Word; var Keys : Integer; var IID : IsamIndDescr); virtual;
function BuildKey(const Data; Key : Integer) : IsamKeyStr; virtual;
procedure UpdateRec(var NewFaxRec);
procedure DeleteRecordPrim(RefNr : LongInt; var Data); virtual;
procedure DeleteRasterizedFile(FN : Str12);
function BuildCreateTimeKey(CreateDate : DateTimeRec; OrigNodeId : Byte) : IsamKeystr;
function BuildToFaxNumberKey(Num : Str19) : IsamKeyStr;
function BuildUserNameKey(Name : Str25) : IsamKeyStr;
function BuildSentTimeKey(SentTime : DateTimeRec; Status : TFaxStatus) : IsamKeyStr;
function BuildStatusKey(Status : TFaxStatus) : IsamKeyStr;
end;
const
FaxInitialized : Boolean = False;
var
Config : TFaxConfig;
FaxDb : TFaxDatabase;
implementation
constructor TFAXDatabase.Init;
begin
with MwConfig do
begin
if not inherited Init(AddBackSlash(Config.WcFaxPath)+'WCFAX',
DatabaseMode = dbSaveMode,
Network <> WcType.NoNet,
FaxCreateTimeKey,
SizeOf(TFaxRec)) then
Fail;
end;
FaxInitialized := True;
end;
destructor TFaxDatabase.Done;
begin
FaxInitialized := False;
inherited Done;
end;
function TFaxDatabase.DataLen(const Data) : Word;
var
F : TFaxRec;
begin
DataLen := SizeOf(TfaxRec);
end;
procedure TFAXDatabase.GetCreateInfo(var Len : Word; var Keys : Integer; var IID : IsamIndDescr);
begin
Len := SizeOf(TFaxRec);
Keys := 5;
IID[FAXCreateTimeKey].KeyL := 8;
IID[FAXCreateTimeKey].AllowDupK := False;
IID[FaxToFAXNumber].KeyL := 20;
IID[FAXToFAXNumber].AllowDupK := True;
IID[FAXUserNameKey].KeyL := 25;
IID[FaxUserNameKey].AllowDupK := True;
IID[FaxSentTimeKey].KeyL := 6;
IID[FaxSentTimeKey].AllowDupK := True;
IID[FaxStatusKey].KeyL := 1;
IID[FaxStatusKey].AllowDupK := True;
end;
function TFaxDataBase.BuildKey(const Data; Key : Integer) : IsamKeyStr;
var
FaxRec : TFaxRec absolute Data;
begin
with FAXRec do
case Key of
FAXCreateTimeKey : BuildKey := WordToKey(OrigNodeId)+
WordToKey(CreateDate.D)+
LongToKey(CreateDate.T);
FAXToFAXNumber : BuildKey := ToNumber;
FAXUserNameKEy : BuildKey := FromName;
FAXSentTimeKEy : if Status <> fsSent then
BuildKey := ''
else
BuildKey := WordToKey(SentDate.D) +
LongToKey(SentDate.T);
FAXStatusKey : BuildKey := Long2Str(Ord(Status));
end;
end;
procedure TFaxDatabase.UpdateRec(var NewFaxRec);
var
RefNr : LongInt;
OldHeader : TFaxRec;
begin
Lock;
if FindKey(FaxUserNameKey, RefNr, BuildKey(NewFaxRec, FaxUserNameKey)) then
begin
GetRec(RefNr, OldHeader);
if IsamOk then
PutRecordPrim(RefNr, OldHeader, NewFaxRec);
end;
Unlock;
end;
procedure TFaxDatabase.DeleteRecordPrim(RefNr : LongInt; var Data);
var
F : File;
Io : Word;
FaxRec : TFaxRec absolute Data;
begin
inherited DeleteRecordPrim(RefNr, Data);
if FaxRec.RasFileName <> '' then
begin
DeleteRasterizedFile(FaxRec.RasFileName);
DeleteRasterizedFile(FaxRec.RasFileName + '.RAS');
end;
end;
procedure TFaxDataBase.DeleteRasterizedFile(Fn : Str12);
var
f : file;
Io : Word;
begin
if ExistFile(AddBackSlash(Config.PendingPath)+FN) then begin
Assign(f, AddBackSlash(Config.PendingPath)+Fn);
Erase(f);
Io := IoResult;
if Io <> 0 then
LogIoError('Unable to delete rasterized file. ' + Fn, Io);
end;
end;
function TFAxDataBase.BuildCreateTimeKey(CreateDate : DateTimeRec; OrigNodeId : Byte) : IsamKeystr;
begin
BuildCreateTimeKey := WordToKey(OrigNodeId)+
WordToKey(CreateDate.D)+
LongToKey(CreateDate.T);
end;
function TFaxDatabase.BuildToFaxNumberKey(Num : Str19) : IsamKeyStr;
begin
BuildToFaxNumberKey := Num;
end;
function TFaxDatabase.BuildUserNameKey(Name : Str25) : IsamKeyStr;
begin
BuildUserNameKey := Name;
end;
function TFaxDatabase.BuildSentTimeKey(SentTime : DateTimeRec; Status : TFaxStatus) : IsamKeyStr;
begin
if Status <> fsSent then
BuildSentTimeKey := ''
else
BuildSentTimeKey := WordToKey(SentTime.D) + LongToKey(SentTime.T);
end;
function TFaxDatabase.BuildStatusKey(Status : TFaxStatus) : IsamKeyStr;
begin
BuildStatusKey := Long2Str(Ord(Status));
end;
end.